#include "eviction/cache-eviction.hpp"

/**
 * \file
 * \ingroup cacheEvict
 * \brief cas::CacheEviction implementation.
 */

namespace cas
{
    SLOG_COMPONENT_DEFINE("CacheEviction");

    double CacheEvictionStatistic::getHitRatio() const
    {
        SLOG_FUNCTION_NOARGS();
        if (requestSize > 0)
        {
            return (double)requestHitSize / requestSize;
        }
        else
        {
            return 0.0;
        }
    }

    double CacheEvictionStatistic::getPrefetchPrecision() const
    {
        SLOG_FUNCTION_NOARGS();
        if (effectivePrefetchSize > 0)
        {
            return (double)effectivePrefetchSize / (effectivePrefetchSize + uselessPrefetchSize);
        }
        else
        {
            return 0.0;
        }
    }

    CacheRequest::CacheRequest(CacheRequestType _type, uint16_t _devno, uint64_t _lba, uint16_t _size)
        : page(_devno, _lba), size(_size), type(_type)
    {
        SLOG_FUNCTION(_type << _devno << _lba << _size);
        if (size == 0)
        {
            SFATAL_ERROR("Size of cache request must be positive");
        }
    }

    CacheEviction::CacheEviction()
    {
        SLOG_FUNCTION_NOARGS();
    }

    CacheEviction::~CacheEviction()
    {
        SLOG_FUNCTION_NOARGS();
    }

    void CacheEviction::setCacheSize(uint32_t cacheSize)
    {
    }

    void CacheEviction::reset()
    {
    }

    uint16_t CacheEviction::lookup(const CacheRequest &request)
    {
        return 0;
    }

    uint32_t CacheEviction::getCacheSize() const
    {
        return 0;
    }

    double CacheEviction::getHitRatio() const
    {
        return stat.getHitRatio();
    }
} // namespace cas
